package org.smart4j.chapter4.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.chapter4.helper.DatabaseHelper;
import org.smart4j.chapter4.model.Customer;
import org.smart4j.framework.annotation.Service;

import java.util.List;
import java.util.Map;

/**
 * 提供客户数据服务
 */
@Service
public class CustomerService {

    private static final Logger logger = LoggerFactory.getLogger(CustomerService.class);


    public List<Customer> getCustomerList(String keyword) {
         return  DatabaseHelper.queryEntityList(Customer.class,"SELECT * FROM customer");
    }

    public Customer getCustomer(long id){
        return DatabaseHelper.queryEntity(Customer.class,"SELECT * FROM Customer WHERE id=?",id);
    }

    public boolean createCustomer(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    public boolean updateCustomer(long id,Map<String,Object> fieldMap){
       return DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    public boolean deleateCustomer(long id){
        return DatabaseHelper.deleteEntity(Customer.class,id);
    }

}
